// 全局文件流下载处理

export const getDownloadFile = (data: BlobPart, filename: string) => {
	const blob = new Blob([data]);

	if ("download" in document.createElement("a")) {
		const downloadElement = document.createElement("a");
		let href = "";
		if (window.URL) {
			href = window.URL.createObjectURL(blob);
		} else {
			href = window.webkitURL.createObjectURL(blob);
		}
		downloadElement.href = href;
		downloadElement.download = filename;
		document.body.appendChild(downloadElement);

		// 下载
		downloadElement.click();

		// 释放内存
		if (window.URL) {
			window.URL.revokeObjectURL(href);
		} else {
			window.webkitURL.revokeObjectURL(href);
		}
		document.body.removeChild(downloadElement);
	} else {
		// navigator.msSaveBlob(blob, filename);
	}
};
